package com.whw.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.whw.entity.Student;
import com.whw.service.StudentService;

@RestController
@RequestMapping("/student")
public class StudentProviderController {
	@Autowired
	private StudentService studentService;
	
	@PostMapping("/save")
	public boolean save(@RequestBody Student student){
		try {
			studentService.save(student);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	@GetMapping("/list")
	public Map<String, Object>list(){
		Map<String, Object>data=new HashMap<String, Object>();
		data.put("code", 1001);
		data.put("list", studentService.list());
		return data;
	}
	
	@GetMapping("/get/{id}")
	public Student get(@PathVariable("id")Integer id){
		return studentService.findById(id);
	}
	
	@GetMapping("/delete/{id}")
	public boolean save(@PathVariable("id")Integer id){
		try {
			studentService.delete(id);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
}
